'''
Monkey patches for content types
'''
from Products.CMFPlone.utils import getToolByName
from apkn.extensions import _

def getAccessorMethod(field_name):
    def getMethod(self, field_name = None):
        no_show = _('You need to log in to see full contact details.')
        pm = getToolByName(self, 'portal_membership', None)
        if pm is not None:
            if pm.isAnonymousUser():
                return no_show
            else:
                if field_name is not None:
                    return self.Schema().get(field_name).get()
                else:
                    return ''
        else:
            return no_show
    return getMethod


getEmail = getAccessorMethod('email')
getEmail2 = getAccessorMethod('email2')
getEmail3 = getAccessorMethod('email3')
getWorkEmail = getAccessorMethod('workEmail')
getWorkEmail2 = getAccessorMethod('workEmail2')
getWorkEmail3 = getAccessorMethod('workEmail3')
getMobilePhone = getAccessorMethod('mobilePhone')
getAddress = getAccessorMethod('address')
